<template>
  <e-table
    ref="eTable"
    @getList="handleGetList"
    :tableData="tableData"
    :columns="columns"
    :loading="loading"
    :total="total"
  >
    <el-table-column slot="selection" align="center" type="selection" width="55" />
  </e-table>
</template>

<script>
import { getHisInboundPay } from '@/api/supplier'
import { getSession, setSession } from '@/utils/util'
export default {
  data() {
    return {
      selectedRows: [],
      tableData: [],
      columns: [
        {
          label: '名称',
          prop: 'goodsName'
        },
        {
          label: '单价',
          prop: 'goodsPrice'
        },
        {
          label: '数量',
          prop: 'goodsQty'
        },
        {
          label: '单位',
          prop: 'qtyUnit'
        },
        {
          label: '总金额',
          prop: 'cost'
        },
        {
          label: '生产厂家',
          prop: 'factoryName'
        }
      ],
      total: 1,
      loading: false
    }
  },
  mounted() {
    let mdl = {}
    const obj = this.$route.params.obj

    if (obj) {
      setSession('record', obj)
      mdl = obj
    } else {
      mdl = getSession('record')
    }
    this.handleGetList({ supplierCode: mdl.supplierCode })
  },
  methods: {
    async handleGetList(param = {}) {
      this.loading = true
      const res = await getHisInboundPay({ ...this.queryParam, ...param })
      if (res && res.data.records.length > 0) {
        const {
          state,
          data: { records, total }
        } = res
        this.tableData = records
        this.total = total
      } else {
        this.tableData = []
        this.total = 1
      }
      this.loading = false
    }
  }
}
</script>
